<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script>
    const bus = new Vue();
    const Child1 = {
      template: `
        <div>
            <h3>这是子组件1</h3>  
        </div>
      `,
      data() {
        return {
          msg: '这是子组件1中的数据'
        }
      },
      methods: {
        fn(){
          console.log(this.msg);
        }
      }
    }
    
    const Home = {
      template: `
        <div>
          <h2 ref="title">这是父组件</h2>  
          <hr/>
          <child1 ref="child"></child1>
          <button ref="btn">按钮</button>
        </div>
      `,
      mounted(){
        // $refs
        console.log(this.$refs);
        this.$refs.btn.style.background="red";
        this.$refs.title.style.color="blue";
        this.$refs.child.fn();
      },
      components: {
        Child1
      }
    }

    Vue.component('Home', Home)

    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>

</html>